package com.example.videoworks.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.videoworks.common.Page;
import com.example.videoworks.common.PageParam;
import com.example.videoworks.controller.request.GetListRequest;
import com.example.videoworks.entity.Principal;
import com.example.videoworks.entity.Work;
import com.example.videoworks.entity.WorkIn;
import com.example.videoworks.mapper.PrincipalMapper;
import com.example.videoworks.mapper.WorkInMapper;
import com.example.videoworks.service.IPrincipalService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;
import java.util.*;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Lily
 * @since 2023-05-11
 */
@Service
public class PrincipalServiceImpl extends ServiceImpl<PrincipalMapper, Principal> implements IPrincipalService {

    @Autowired
    private PrincipalMapper principalMapper;

    @Override
    public Page<Principal> getPrincipalListByName(GetListRequest request, String name) {
        if (request == null) return null;
        PageParam pageParam = request.getPageParam();
        PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize(), pageParam.getOrderBy()/*"uploadTime asc"*/);//asc顺序 desc倒序
        List<Principal> list = principalMapper.searchName(name);
        return new Page(new PageInfo<>(list));
    }

    @Override
    public Page<Principal> getPrincipalListByProfession(GetListRequest request, String profession) {
        if (request == null) return null;
        PageParam pageParam = request.getPageParam();
        PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize(), pageParam.getOrderBy()/*"uploadTime asc"*/);//asc顺序 desc倒序
        List<Principal> list = principalMapper.filtrateProfession(profession);
        return new Page(new PageInfo<>(list));
    }

    @Override
    public Page<Principal> getPrincipalListByBirthYear(GetListRequest request, String birthYear) {
        if (request == null) return null;
        PageParam pageParam = request.getPageParam();
        PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize(), pageParam.getOrderBy()/*"uploadTime asc"*/);//asc顺序 desc倒序
        List<Principal> list = principalMapper.filtrateBirthYear(birthYear);
        return new Page(new PageInfo<>(list));
    }

    @Override
    public Principal getPrincipalById(String personId) {
        Principal principal=principalMapper.principalDetails(personId);
        return  principal;
    }

}
